#pragma strict

var playerHSpeed:float;
var playerVSpeed:float;
var projectGameObject:Transform;
var life:float;
var explotionPrefab:GameObject;
function Start () {
	AutoEnemy.playerLife=AutoEnemy.initplaylift=life;
}

function Update () {
	var amToMove=Input.GetAxis("Horizontal")*playerHSpeed*Time.deltaTime;
	var amtoMoveUp=Input.GetAxis("Vertical")*playerHSpeed*Time.deltaTime;
	this.transform.Translate(Vector3.right*amToMove);
	this.transform.Translate(Vector3.up*amtoMoveUp);
	if(this.transform.position.x>=8.15) {
		this.transform.position=new Vector3(-8.15,this.transform.position.y);
	}
	if(this.transform.position.x<=-8.16)
	{
		this.transform.position=new Vector3(8.15,this.transform.position.y);
	}
	if(this.transform.position.y>=5.5) {
		this.transform.position=new Vector3(this.transform.position.x,5.5);
	}
	if(this.transform.position.y<=-3.2)
	{
		this.transform.position=new Vector3(this.transform.position.x,-3.2);
	}
	if(Input.GetKeyDown(KeyCode.F))
	{
		Instantiate(projectGameObject,Vector3(this.transform.position.x,this.transform.position.y+this.transform.rotation.y*2,this.transform.position.z),Quaternion.identity);
	}
}

//发生碰撞后减血
function OnTriggerEnter (other:Collider ) {
	//如果碰撞体为敌方炮弹或物体
	if(other.GetComponent(Enemy)){
		var enemy:Enemy;
		enemy=other.GetComponent(Enemy);
		AutoEnemy.playerLife-=enemy.hurt;
		
	}else if(other.GetComponent(EnemyProjectile))
	{
		var paodan:EnemyProjectile;
		paodan=other.GetComponent(EnemyProjectile);
		AutoEnemy.playerLife-=paodan.hurt;
	}
	if(AutoEnemy.playerLife<=0)//生命值小于0--死了
		{
			doparticleSystem();
			Destroy(this.gameObject);
			AutoEnemy.isDeath=true;
		}
}


//撞毁后爆炸
function doparticleSystem()
{
	Instantiate(explotionPrefab,this.transform.position,this.transform.rotation);
}